Change in openvpn[master]: ssl_openssl: Fix some CRL mixups
A message that is not in the archive (sent off-list or not yet received): gerrit.1760995553000.I31ac2a763209114267c35c4a9182a12d8d82f6fe@...2715...
Attention is currently required from: flichtenheld, plaisthos.
Hello plaisthos, flichtenheld,
I'd like you to do a code review.
Please visit
http://gerrit.openvpn.net/c/openvpn/+/1289?usp=email
to review the following change.
Change subject: ssl_openssl: Fix some CRL mixups
......................................................................
ssl_openssl: Fix some CRL mixups
There are two ways to load CRLs in OpenSSL. They can be loaded at the X509_STORE, shared across verifications, or loaded per verification at the X509_STORE_CTX.
OpenVPN currently does the former. However, it also supports CRL reloading, and tries to reload the CRL file before each connection. OpenSSL does not really have a good way to unload objects from an X509_STORE. OpenVPN currently does it by grabbing the STACK_OF(X509_OBJECT) out of the X509_STORE and manually deleting all the CRLs from it.
This mutates an OpenSSL internal object which bumps into problems if OpenSSL ever switches to a more efficient representation. See
https://github.com/openssl/openssl/pull/28599
(It's also not thread-safe, though it doesn't look like that impacts OpenVPN? Actually even reading that list doesn't work. See CVE-2024-0397. This OpenSSL API was simply broken.)
Additionally, this seems to cause two OpenVPN features to not work together. I gather backend_tls_ctx_reload_crl is trying to clear the CRLs loaded from last time it ran. But tls_ctx_load_ca with a ca_file can also load CRLs. tls_ctx_load_ca with ca_path will also pick up CRLs and backend_tls_ctx_reload_crl actually ends up clobbering some state X509_LOOKUP_hash_dir internally maintains on the X509_STORE. Likewise, tls_verify_crl_missing can get confused between backend_tls_ctx_reload_crl's crl_file-based CRLs and CRLs from tls_ctx_load_ca.
Avoid all this by tracking the two CRLs separately. crl_file-based CRLs now go onto a STACK_OF(X509_CRL) tracked on the tls_root_ctx. Now this field can be freely reloaded by OpenVPN without reconfiguring OpenSSL. Instead, pass the current value into OpenSSL at verification time. To do so, we need to use the SSL_CTX_set_cert_verify_callback, which allows swapping out the X509_verify_cert call, and also tweaking the X509_STORE_CTX configuration before starting certificate verification.
Context: SSL_CTX_set_cert_verify_callback and the existing verify_callback are not the same. SSL_CTX_set_cert_verify_callback wraps the verification while verify_callback is called multiple times throughout verification. It's too late to reconfigure X509_STORE_CTX in verify_callback. verify_callback is usually not what you want. Sometimes current_cert and error_depth don't quite line up, and cert_hash_remember may end up called multiple times for a single certificate.
I suspect some of the other verify_callback logic would also be better done in the new callback, but I've left it alone to keep this change minimal. verify_callback is really only usable for suppressing errors. Application bookkeeping is better down elsewhere.
---
M src/openvpn/openssl_compat.h
M src/openvpn/ssl_openssl.c
M src/openvpn/ssl_openssl.h
M src/openvpn/ssl_verify_openssl.c
4 files changed, 34 insertions(+), 54 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/89/1289/1
src/openvpn/openssl_compat.h +0 -15
@@ -52,21 +52,6 @@/* Functionality missing in LibreSSL before 3.5 */ #if defined(LIBRESSL_VERSION_NUMBER ) &&LIBRESSL_VERSION_NUMBER <0x3050000fL -/** -* Destroy a X509 object -* -* @param obj X509 object -*/ -static inline void -X509_OBJECT_free (X509_OBJECT *obj) -{ -if (obj) - { -X509_OBJECT_free_contents (obj); -OPENSSL_free (obj); - } -} -#define EVP_CTRL_AEAD_SET_TAG EVP_CTRL_GCM_SET_TAG#define EVP_CTRL_AEAD_GET_TAG EVP_CTRL_GCM_GET_TAG#endif
src/openvpn/ssl_openssl.c +32 -22
101 lines not on this page · raw message
src/openvpn/ssl_openssl.h +1 -0
@@ -41,6 +41,7 @@SSL_CTX *ctx;time_t crl_last_mtime;off_t crl_last_size; +STACK_OF (X509_CRL ) *crls; };struct key_state_ssl
src/openvpn/ssl_verify_openssl.c +1 -17
@@ -792,23 +792,7 @@ return false; } -X509_STORE *store =SSL_CTX_get_cert_store (opt->ssl_ctx.ctx); -if (!store) - { -crypto_msg (M_FATAL ,"Cannot get certificate store" ); - } - -STACK_OF (X509_OBJECT ) *objs =X509_STORE_get0_objects (store); -for (int i =0 ; i <sk_X509_OBJECT_num (objs); i++) - { -X509_OBJECT *obj =sk_X509_OBJECT_value (objs, i); -ASSERT (obj); -if (X509_OBJECT_get_type (obj) ==X509_LU_CRL ) - { -return false; - } - } -return true; +return opt->ssl_ctx.crls ==NULL ||sk_X509_CRL_num (opt->ssl_ctx.crls) ==0 ; }#endif /* defined(ENABLE_CRYPTO_OPENSSL) */
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1289?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I31ac2a763209114267c35c4a9182a12d8d82f6fe
Gerrit-Change-Number: 1289
Gerrit-PatchSet: 1
Gerrit-Owner: davidben <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Attention is currently required from: davidben, flichtenheld.
plaisthos has posted comments on this change by davidben. ( http://gerrit.openvpn.net/c/openvpn/+/1289?usp=email )
Change subject: ssl_openssl: Fix some CRL mixups
......................................................................
Patch Set 2:
(1 comment)
Patchset:
PS2:
I pushed a rebased version without changes to trigger the building on buildbots
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1289?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I31ac2a763209114267c35c4a9182a12d8d82f6fe
Gerrit-Change-Number: 1289
Gerrit-PatchSet: 2
Gerrit-Owner: davidben <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: davidben <[email protected]...>
Gerrit-Comment-Date: Tue, 09 Dec 2025 14:05:42 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Attention is currently required from: davidben, flichtenheld.
plaisthos has posted comments on this change by davidben. ( http://gerrit.openvpn.net/c/openvpn/+/1289?usp=email )
Change subject: ssl_openssl: Fix some CRL mixups
......................................................................
Patch Set 2: Code-Review-2
(1 comment)
Patchset:
PS2:
There seem to be a problem when the CRL file gets invalid:
I setup OpenVPN with a normal setup
(gdb) run
Starting program: /home/arne/openvpn-cmake-debug/openvpn --server 10.33.0.0 255.255.255.0 --server-ipv6 fd00:f00f:babe::1/64 --topology subnet --cert /home/arne/ut-ca/server.pem --key /home/arne/ut-ca/server.key --dev tun --verb 4 --data-ciphers AES-256-GCM:AES-128-GCM:AES-192-GCM --tun-mtu 1400 --keepalive 10 25 --push explicit-exit-notify\ 3 --verb 4 --crl-verify /home/arne/ut-ca/ca.crl --ca /home/arne/ut-ca/ca.pem
[...]
Then connected a client and that went fine.
Then I replaced the CRL file with an invalid one:
rm ca.crl && touch ca.crl
Connecting the client again first works fine (connection gets rejected)
2025-12-09 14:43:11 us=78031 Connection Attempt MULTI: multi_create_instance called 2025-12-09 14:43:11 us=78143 udp4:192.168.188.75:58649 Re-using SSL/TLS context 2025-12-09 14:43:11 us=78267 udp4:192.168.188.75:58649 Control Channel MTU parms [ mss_fix:0 max_frag:0 tun_mtu:1250 tun_max_mtu:0 headroom:126 payload:1600 tailroom:126 ET:0 ] 2025-12-09 14:43:11 us=78293 udp4:192.168.188.75:58649 Data Channel MTU parms [ mss_fix:0 max_frag:0 tun_mtu:1400 tun_max_mtu:1600 headroom:136 payload:1768 tailroom:562 ET:0 ] 2025-12-09 14:43:11 us=82903 udp4:192.168.188.75:58649 VERIFY WARNING: depth=0, unable to get certificate CRL: C=KG, ST=NA, O=OpenVPN-TEST, CN=Test-Client, [email protected]... 2025-12-09 14:43:11 us=83007 udp4:192.168.188.75:58649 VERIFY WARNING: depth=1, unable to get certificate CRL: C=KG, ST=NA, L=BISHKEK, O=OpenVPN-TEST, [email protected]... 2025-12-09 14:43:11 us=83165 udp4:192.168.188.75:58649 VERIFY ERROR: CRL not loaded 2025-12-09 14:43:11 us=83238 udp4:192.168.188.75:58649 Sent fatal SSL alert: unknown CA 2025-12-09 14:43:11 us=83289 udp4:192.168.188.75:58649 OpenSSL: error:0A000086:SSL routines::certificate verify failed: 2025-12-09 14:43:11 us=83330 udp4:192.168.188.75:58649 TLS_ERROR: BIO read tls_read_plaintext error 2025-12-09 14:43:11 us=83358 udp4:192.168.188.75:58649 TLS Error: TLS object -> incoming plaintext read error 2025-12-09 14:43:11 us=83405 udp4:192.168.188.75:58649 TLS Error: TLS handshake failed 2025-12-09 14:43:11 us=83550 Warning buffer of freed TLS session is still in use (session->key[0].send_reliable->array[0]) 2025-12-09 14:43:11 us=83686 udp4:192.168.188.75:58649 SIGUSR1[soft,tls-error] received, client-instance restarting 2025-12-09 14:43:11 us=83759 Packet (P_CONTROL_V1) with invalid or missing SID from [AF_INET]192.168.188.75:58649 or wrong packet id 2025-12-09 14:43:13 us=380641 Packet (P_CONTROL_V1) with invalid or missing SID from [AF_INET]192.168.188.75:58649 or wrong packet id 2025-12-09 14:43:13 us=380799 Packet (P_CONTROL_V1) with invalid or missing SID from [AF_INET]192.168.188.75:58649 or wrong packet id
But then reconnecting again leads to a segfault:
2025-12-09 14:43:14 us=950844 Connection Attempt MULTI: multi_create_instance called 2025-12-09 14:43:14 us=950963 udp4:192.168.188.75:59576 Re-using SSL/TLS context 2025-12-09 14:43:14 us=951112 udp4:192.168.188.75:59576 Control Channel MTU parms [ mss_fix:0 max_frag:0 tun_mtu:1250 tun_max_mtu:0 headroom:126 payload:1600 tailroom:126 ET:0 ] 2025-12-09 14:43:14 us=951162 udp4:192.168.188.75:59576 Data Channel MTU parms [ mss_fix:0 max_frag:0 tun_mtu:1400 tun_max_mtu:1600 headroom:136 payload:1768 tailroom:562 ET:0 ] 2025-12-09 14:43:14 us=955828 udp4:192.168.188.75:59576 VERIFY WARNING: depth=0, unable to get certificate CRL: C=KG, ST=NA, O=OpenVPN-TEST, CN=Test-Client, [email protected]... 2025-12-09 14:43:14 us=955883 udp4:192.168.188.75:59576 VERIFY WARNING: depth=1, unable to get certificate CRL: C=KG, ST=NA, L=BISHKEK, O=OpenVPN-TEST, [email protected]... 2025-12-09 14:43:14 us=955942 udp4:192.168.188.75:59576 VERIFY ERROR: CRL not loaded 2025-12-09 14:43:14 us=955961 udp4:192.168.188.75:59576 Sent fatal SSL alert: unknown CA 2025-12-09 14:43:14 us=955981 udp4:192.168.188.75:59576 OpenSSL: error:0A000086:SSL routines::certificate verify failed: 2025-12-09 14:43:14 us=955988 udp4:192.168.188.75:59576 TLS_ERROR: BIO read tls_read_plaintext error 2025-12-09 14:43:14 us=955996 udp4:192.168.188.75:59576 TLS Error: TLS object -> incoming plaintext read error 2025-12-09 14:43:14 us=956005 udp4:192.168.188.75:59576 TLS Error: TLS handshake failed 2025-12-09 14:43:14 us=956018 Warning buffer of freed TLS session is still in use (session->key[0].send_reliable->array[0]) 2025-12-09 14:43:14 us=956061 udp4:192.168.188.75:59576 SIGUSR1[soft,tls-error] received, client-instance restarting 2025-12-09 14:43:14 us=956089 Packet (P_CONTROL_V1) with invalid or missing SID from [AF_INET]192.168.188.75:59576 or wrong packet id
\
2025-12-09 14:43:28 us=286692 Connection Attempt MULTI: multi_create_instance called 2025-12-09 14:43:28 us=286782 udp4:192.168.188.75:60010 Re-using SSL/TLS context 2025-12-09 14:43:28 us=287024 udp4:192.168.188.75:60010 OpenSSL: error:0308010C:digital envelope routines::unsupported:Global default library context, Algorithm (none : 0), Properties (<null>) 2025-12-09 14:43:28 us=287031 udp4:192.168.188.75:60010 OpenSSL: error:0480006C:PEM routines::no start line: 2025-12-09 14:43:28 us=287034 udp4:192.168.188.75:60010 CRL: cannot read CRL from file /home/arne/ut-ca/ca.crl 2025-12-09 14:43:28 us=287036 udp4:192.168.188.75:60010 CRL: loaded 1 CRLs from file /home/arne/ut-ca/ca.crl 2025-12-09 14:43:28 us=287058 udp4:192.168.188.75:60010 Control Channel MTU parms [ mss_fix:0 max_frag:0 tun_mtu:1250 tun_max_mtu:0 headroom:126 payload:1600 tailroom:126 ET:0 ] 2025-12-09 14:43:28 us=287061 udp4:192.168.188.75:60010 Data Channel MTU parms [ mss_fix:0 max_frag:0 tun_mtu:1400 tun_max_mtu:1600 headroom:136 payload:1768 tailroom:562 ET:0 ] 2025-12-09 14:43:28 us=292177 udp4:192.168.188.75:60010 VERIFY OK: depth=1, C=KG, ST=NA, L=BISHKEK, O=OpenVPN-TEST, [email protected]... 2025-12-09 14:43:28 us=292774 udp4:192.168.188.75:60010 VERIFY OK: depth=0, C=KG, ST=NA, O=OpenVPN-TEST, CN=Test-Client, [email protected]... 2025-12-09 14:43:28 us=293487 udp4:192.168.188.75:60010 peer info: IV_VER=2.7_rc3 2025-12-09 14:43:28 us=293559 udp4:192.168.188.75:60010 peer info: IV_PLAT=mac 2025-12-09 14:43:28 us=293612 udp4:192.168.188.75:60010 peer info: IV_TCPNL=1 2025-12-09 14:43:28 us=293639 udp4:192.168.188.75:60010 peer info: IV_MTU=1600 2025-12-09 14:43:28 us=293652 udp4:192.168.188.75:60010 peer info: IV_NCP=2 2025-12-09 14:43:28 us=293664 udp4:192.168.188.75:60010 peer info: IV_CIPHERS=AES-256-GCM:AES-128-GCM:CHACHA20-POLY1305 2025-12-09 14:43:28 us=293704 udp4:192.168.188.75:60010 peer info: IV_PROTO=8094 2025-12-09 14:43:28 us=293775 udp4:192.168.188.75:60010 peer info: ID=e7afaf 2025-12-09 14:43:28 us=293793 udp4:192.168.188.75:60010 peer info: IV_LZO_STUB=1 2025-12-09 14:43:28 us=293799 udp4:192.168.188.75:60010 peer info: IV_COMP_STUB=1 2025-12-09 14:43:28 us=293804 udp4:192.168.188.75:60010 peer info: IV_COMP_STUBv2=1 2025-12-09 14:43:28 us=293983 udp4:192.168.188.75:60010 TLS: move_session: dest=TM_ACTIVE src=TM_INITIAL reinit_src=1 2025-12-09 14:43:28 us=294092 udp4:192.168.188.75:60010 TLS: tls_multi_process: initial untrusted session promoted to trusted 2025-12-09 14:43:28 us=294701 udp4:192.168.188.75:60010 Control Channel: TLSv1.3, cipher TLSv1.3 TLS_AES_256_GCM_SHA384, peer certificate: 2048 bits RSA, signature: ecdsa-with-SHA256, peer temporary key: 768 bits X25519MLKEM768, peer signing digest/type: rsa_pss_rsae_sha256 RSASSA-PSS, key agreement: X25519MLKEM768 2025-12-09 14:43:28 us=294754 udp4:192.168.188.75:60010 [Test-Client] Peer Connection Initiated with [AF_INET]192.168.188.75:60010 2025-12-09 14:43:28 us=294784 Test-Client/udp4:192.168.188.75:60010 MULTI_sva: pool returned IPv4=10.33.0.2, IPv6=fd00:f00f:babe::1001 2025-12-09 14:43:28 us=295142 Test-Client/udp4:192.168.188.75:60010 Data Channel MTU parms [ mss_fix:1360 max_frag:0 tun_mtu:1400 tun_max_mtu:1600 headroom:136 payload:1768 tailroom:562 ET:0 ] 2025-12-09 14:43:28 us=295205 Test-Client/udp4:192.168.188.75:60010 Outgoing dynamic tls-crypt: Cipher 'AES-256-CTR' initialized with 256 bit key 2025-12-09 14:43:28 us=295223 Test-Client/udp4:192.168.188.75:60010 Outgoing dynamic tls-crypt: Using 256 bit message hash 'SHA256' for HMAC authentication 2025-12-09 14:43:28 us=295230 Test-Client/udp4:192.168.188.75:60010 Incoming dynamic tls-crypt: Cipher 'AES-256-CTR' initialized with 256 bit key 2025-12-09 14:43:28 us=295238 Test-Client/udp4:192.168.188.75:60010 Incoming dynamic tls-crypt: Using 256 bit message hash 'SHA256' for HMAC authentication 2025-12-09 14:43:28 us=295297 Test-Client/udp4:192.168.188.75:60010 MULTI: Learn: 10.33.0.2 -> Test-Client/udp4:192.168.188.75:60010 2025-12-09 14:43:28 us=295333 Test-Client/udp4:192.168.188.75:60010 MULTI: primary virtual IP for Test-Client/udp4:192.168.188.75:60010: 10.33.0.2 2025-12-09 14:43:28 us=295352 Test-Client/udp4:192.168.188.75:60010 MULTI: Learn: fd00:f00f:babe::1001 -> Test-Client/udp4:192.168.188.75:60010 2025-12-09 14:43:28 us=295359 Test-Client/udp4:192.168.188.75:60010 MULTI: primary virtual IPv6 for Test-Client/udp4:192.168.188.75:60010: fd00:f00f:babe::1001 2025-12-09 14:43:28 us=295389 Test-Client/udp4:192.168.188.75:60010 SENT CONTROL [Test-Client]: 'PUSH_REPLY,explicit-exit-notify 3,tun-ipv6,route-gateway 10.33.0.1,topology subnet,ping 10,ping-restart 25,ifconfig-ipv6 fd00:f00f:babe::1001/64 fd00:f00f:babe::2,ifconfig 10.33.0.2 255.255.255.0,peer-id 0,cipher AES-256-GCM,protocol-flags cc-exit tls-ekm dyn-tls-crypt,tun-mtu 1400' (status=1) 2025-12-09 14:43:29 us=319915 Test-Client/udp4:192.168.188.75:60010 Data Channel: cipher 'AES-256-GCM', rx-peer-id: 0, tx-peer-id: 0 2025-12-09 14:43:29 us=320027 Test-Client/udp4:192.168.188.75:60010 Timers: ping 10, ping-restart 50 2025-12-09 14:43:29 us=320051 Test-Client/udp4:192.168.188.75:60010 Protocol options: protocol-flags cc-exit tls-ekm dyn-tls-crypt 2025-12-09 14:43:37 us=293135 Test-Client/udp4:192.168.188.75:60010 CC-EEN exit message received by peer 2025-12-09 14:43:37 us=293196 Test-Client/udp4:192.168.188.75:60010 Delayed exit in 5 seconds 2025-12-09 14:43:42 us=321905 Test-Client/udp4:192.168.188.75:60010 SIGTERM[soft,delayed-exit] received, client-instance exiting 2025-12-09 14:43:42 us=322142 ovpn_handle_peer: received data for a non-existing peer 0 2025-12-09 14:43:58 us=52079 Connection Attempt MULTI: multi_create_instance called 2025-12-09 14:43:58 us=52177 udp4:192.168.188.75:58033 Re-using SSL/TLS context 2025-12-09 14:43:58 us=52342 udp4:192.168.188.75:58033 OpenSSL: error:0308010C:digital envelope routines::unsupported:Global default library context, Algorithm (none : 0), Properties (<null>) 2025-12-09 14:43:58 us=52349 udp4:192.168.188.75:58033 OpenSSL: error:0480006C:PEM routines::no start line: 2025-12-09 14:43:58 us=52352 udp4:192.168.188.75:58033 CRL: cannot read CRL from file /home/arne/ut-ca/ca.crl 2025-12-09 14:43:58 us=52354 udp4:192.168.188.75:58033 CRL: loaded 0 CRLs from file /home/arne/ut-ca/ca.crl 2025-12-09 14:43:58 us=52375 udp4:192.168.188.75:58033 Control Channel MTU parms [ mss_fix:0 max_frag:0 tun_mtu:1250 tun_max_mtu:0 headroom:126 payload:1600 tailroom:126 ET:0 ] 2025-12-09 14:43:58 us=52378 udp4:192.168.188.75:58033 Data Channel MTU parms [ mss_fix:0 max_frag:0 tun_mtu:1400 tun_max_mtu:1600 headroom:136 payload:1768 tailroom:562 ET:0 ] 2025-12-09 14:43:58 us=57062 udp4:192.168.188.75:58033 VERIFY WARNING: depth=0, unable to get certificate CRL: C=KG, ST=NA, O=OpenVPN-TEST, CN=Test-Client, [email protected]... 2025-12-09 14:43:58 us=57086 udp4:192.168.188.75:58033 VERIFY WARNING: depth=1, unable to get certificate CRL: C=KG, ST=NA, L=BISHKEK, O=OpenVPN-TEST, [email protected]... 2025-12-09 14:43:58 us=57129 udp4:192.168.188.75:58033 VERIFY ERROR: CRL not loaded 2025-12-09 14:43:58 us=57142 udp4:192.168.188.75:58033 Sent fatal SSL alert: unknown CA 2025-12-09 14:43:58 us=57155 udp4:192.168.188.75:58033 OpenSSL: error:0A000086:SSL routines::certificate verify failed: 2025-12-09 14:43:58 us=57157 udp4:192.168.188.75:58033 TLS_ERROR: BIO read tls_read_plaintext error 2025-12-09 14:43:58 us=57160 udp4:192.168.188.75:58033 TLS Error: TLS object -> incoming plaintext read error 2025-12-09 14:43:58 us=57164 udp4:192.168.188.75:58033 TLS Error: TLS handshake failed 2025-12-09 14:43:58 us=57175 Warning buffer of freed TLS session is still in use (session->key[0].send_reliable->array[0]) 2025-12-09 14:43:58 us=57217 udp4:192.168.188.75:58033 SIGUSR1[soft,tls-error] received, client-instance restarting 2025-12-09 14:43:58 us=57246 Packet (P_CONTROL_V1) with invalid or missing SID from [AF_INET]192.168.188.75:58033 or wrong packet id 2025-12-09 14:43:59 us=165790 Packet (P_CONTROL_V1) with invalid or missing SID from [AF_INET]192.168.188.75:58033 or wrong packet id 2025-12-09 14:43:59 us=165885 Packet (P_CONTROL_V1) with invalid or missing SID from [AF_INET]192.168.188.75:58033 or wrong packet id 2025-12-09 14:44:05 us=928745 Connection Attempt MULTI: multi_create_instance called 2025-12-09 14:44:05 us=928929 udp4:192.168.188.75:54942 Re-using SSL/TLS context
Program received signal SIGSEGV, Segmentation fault.0x00007ffff7ba7cc5 in OPENSSL_sk_pop_free () from /lib/x86_64-linux-gnu/libcrypto.so.3
(gdb) bt
#0 0x00007ffff7ba7cc5 in OPENSSL_sk_pop_free () from /lib/x86_64-linux-gnu/libcrypto.so.3
#1 0x000055555561339a in backend_tls_ctx_reload_crl (ssl_ctx=0x55555576f260, crl_file=0x7fffffffe5f2 "/home/arne/ut-ca/ca.crl", crl_inline=false)
at /home/arne/openvpn-git/src/openvpn/ssl_openssl.c:1348
#2 0x0000555555608148 in tls_ctx_reload_crl (ssl_ctx=0x55555576f260, crl_file=0x7fffffffe5f2 "/home/arne/ut-ca/ca.crl", crl_file_inline=false)
at /home/arne/openvpn-git/src/openvpn/ssl.c:503 #3 0x0000555555608e63 in key_state_init (session=0x55555576f970, ks=0x5555557700e0) at /home/arne/openvpn-git/src/openvpn/ssl.c:879 #4 0x000055555560924c in tls_session_init (multi=0x55555576f260, session=0x55555576f970) at /home/arne/openvpn-git/src/openvpn/ssl.c:1023 #5 0x0000555555609748 in tls_multi_init_finalize (multi=0x55555576f260, tls_mtu=1250) at /home/arne/openvpn-git/src/openvpn/ssl.c:1177 #6 0x0000555555592659 in do_init_frame_tls (c=0x55555577f2c0) at /home/arne/openvpn-git/src/openvpn/init.c:3462 #7 0x0000555555594b45 in init_instance (c=0x55555577f2c0, env=0x5555556fdb30, flags=10) at /home/arne/openvpn-git/src/openvpn/init.c:4613 #8 0x0000555555595625 in inherit_context_child (dest=0x55555577f2c0, src=0x7fffffffb5d8, sock=0x5555556fd8e0) at /home/arne/openvpn-git/src/openvpn/init.c:4914 #9 0x00005555555aba4b in multi_create_instance (m=0x7fffffffb510, real=0x7fffffffafb0, sock=0x5555556fd8e0) at /home/arne/openvpn-git/src/openvpn/multi.c:737
#10 0x00005555555a8bec in multi_get_create_instance_udp (m=0x7fffffffb510, floated=0x7fffffffb3b0, sock=0x5555556fd8e0) at /home/arne/openvpn-git/src/openvpn/mudp.c:269 #11 0x00005555555b198e in multi_process_incoming_link (m=0x7fffffffb510, instance=0x0, mpp_flags=5, sock=0x5555556fd8e0) at /home/arne/openvpn-git/src/openvpn/multi.c:3357 #12 0x00005555555a8fd1 in multi_process_io_udp (m=0x7fffffffb510, sock=0x5555556fd8e0) at /home/arne/openvpn-git/src/openvpn/mudp.c:357
#13 0x00005555555b54b5 in multi_io_process_io (m=0x7fffffffb510) at /home/arne/openvpn-git/src/openvpn/multi_io.c:468
#14 0x00005555555b3629 in tunnel_server_loop (multi=0x7fffffffb510) at /home/arne/openvpn-git/src/openvpn/multi.c:4197
#15 0x00005555555b37da in tunnel_server (top=0x7fffffffcb50) at /home/arne/openvpn-git/src/openvpn/multi.c:4249
#16 0x00005555555b8110 in openvpn_main (argc=31, argv=0x7fffffffe168) at /home/arne/openvpn-git/src/openvpn/openvpn.c:309
#17 0x00005555555b8256 in main (argc=31, argv=0x7fffffffe168) at /home/arne/openvpn-git/src/openvpn/openvpn.c:384
(gdb)
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1289?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I31ac2a763209114267c35c4a9182a12d8d82f6fe
Gerrit-Change-Number: 1289
Gerrit-PatchSet: 2
Gerrit-Owner: davidben <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: davidben <[email protected]...>
Gerrit-Comment-Date: Tue, 09 Dec 2025 14:47:47 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Attention is currently required from: davidben, flichtenheld.
plaisthos has posted comments on this change by davidben. ( http://gerrit.openvpn.net/c/openvpn/+/1289?usp=email )
Change subject: ssl_openssl: Fix some CRL mixups
......................................................................
Patch Set 2:
(1 comment)
Patchset:
PS2:
So I debugged this further and the root cause is that tls_root_ctx is shared/copied around between tls_options and key_schedule context. With the old implementation this was not a problem since the pointer never changed. But with the new implementation the pointer is freed and changed in one instance and the other instance will then still try to free the old pointer and that causes a free on an invalid pointer and that segfaults.
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1289?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I31ac2a763209114267c35c4a9182a12d8d82f6fe
Gerrit-Change-Number: 1289
Gerrit-PatchSet: 2
Gerrit-Owner: davidben <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: davidben <[email protected]...>
Gerrit-Comment-Date: Wed, 10 Dec 2025 13:53:32 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Attention is currently required from: davidben, flichtenheld.
plaisthos has posted comments on this change by davidben. ( http://gerrit.openvpn.net/c/openvpn/+/1289?usp=email )
Change subject: ssl_openssl: Fix some CRL mixups
......................................................................
Patch Set 2:
(1 comment)
Patchset:
PS2:
In do_init_crypto_tls we do
to.ssl_ctx = c->c1.ks.ssl_ctx;
which copies the context and also the stack
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1289?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I31ac2a763209114267c35c4a9182a12d8d82f6fe
Gerrit-Change-Number: 1289
Gerrit-PatchSet: 2
Gerrit-Owner: davidben <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: davidben <[email protected]...>
Gerrit-Comment-Date: Wed, 10 Dec 2025 13:56:15 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Attention is currently required from: davidben, flichtenheld.
plaisthos has uploaded a new patch set (#3) to the change originally created by davidben. ( http://gerrit.openvpn.net/c/openvpn/+/1289?usp=email )
Change subject: ssl_openssl: Fix some CRL mixups
......................................................................
ssl_openssl: Fix some CRL mixups
There are two ways to load CRLs in OpenSSL. They can be loaded at the X509_STORE, shared across verifications, or loaded per verification at the X509_STORE_CTX.
OpenVPN currently does the former. However, it also supports CRL reloading, and tries to reload the CRL file before each connection. OpenSSL does not really have a good way to unload objects from an X509_STORE. OpenVPN currently does it by grabbing the STACK_OF(X509_OBJECT) out of the X509_STORE and manually deleting all the CRLs from it.
This mutates an OpenSSL internal object which bumps into problems if OpenSSL ever switches to a more efficient representation. See
https://github.com/openssl/openssl/pull/28599
(It's also not thread-safe, though it doesn't look like that impacts OpenVPN? Actually even reading that list doesn't work. See CVE-2024-0397. This OpenSSL API was simply broken.)
Additionally, this seems to cause two OpenVPN features to not work together. I gather backend_tls_ctx_reload_crl is trying to clear the CRLs loaded from last time it ran. But tls_ctx_load_ca with a ca_file can also load CRLs. tls_ctx_load_ca with ca_path will also pick up CRLs and backend_tls_ctx_reload_crl actually ends up clobbering some state X509_LOOKUP_hash_dir internally maintains on the X509_STORE. Likewise, tls_verify_crl_missing can get confused between backend_tls_ctx_reload_crl's crl_file-based CRLs and CRLs from tls_ctx_load_ca.
Avoid all this by tracking the two CRLs separately. crl_file-based CRLs now go onto a STACK_OF(X509_CRL) tracked on the tls_root_ctx. Now this field can be freely reloaded by OpenVPN without reconfiguring OpenSSL. Instead, pass the current value into OpenSSL at verification time. To do so, we need to use the SSL_CTX_set_cert_verify_callback, which allows swapping out the X509_verify_cert call, and also tweaking the X509_STORE_CTX configuration before starting certificate verification.
Context: SSL_CTX_set_cert_verify_callback and the existing verify_callback are not the same. SSL_CTX_set_cert_verify_callback wraps the verification while verify_callback is called multiple times throughout verification. It's too late to reconfigure X509_STORE_CTX in verify_callback. verify_callback is usually not what you want. Sometimes current_cert and error_depth don't quite line up, and cert_hash_remember may end up called multiple times for a single certificate.
I suspect some of the other verify_callback logic would also be better done in the new callback, but I've left it alone to keep this change minimal. verify_callback is really only usable for suppressing errors. Application bookkeeping is better down elsewhere.
---
M src/openvpn/openssl_compat.h
M src/openvpn/ssl_openssl.c
M src/openvpn/ssl_openssl.h
M src/openvpn/ssl_verify_openssl.c
4 files changed, 34 insertions(+), 54 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/89/1289/3
src/openvpn/openssl_compat.h +0 -15
@@ -52,21 +52,6 @@/* Functionality missing in LibreSSL before 3.5 */ #if defined(LIBRESSL_VERSION_NUMBER ) &&LIBRESSL_VERSION_NUMBER <0x3050000fL -/** -* Destroy a X509 object -* -* @param obj X509 object -*/ -static inline void -X509_OBJECT_free (X509_OBJECT *obj) -{ -if (obj) - { -X509_OBJECT_free_contents (obj); -OPENSSL_free (obj); - } -} -#define EVP_CTRL_AEAD_SET_TAG EVP_CTRL_GCM_SET_TAG#define EVP_CTRL_AEAD_GET_TAG EVP_CTRL_GCM_GET_TAG#endif
src/openvpn/ssl_openssl.c +32 -22
101 lines not on this page · raw message
src/openvpn/ssl_openssl.h +1 -0
@@ -41,6 +41,7 @@SSL_CTX *ctx;time_t crl_last_mtime;off_t crl_last_size; +STACK_OF (X509_CRL ) *crls; };struct key_state_ssl
src/openvpn/ssl_verify_openssl.c +1 -17
@@ -799,23 +799,7 @@ return false; } -X509_STORE *store =SSL_CTX_get_cert_store (opt->ssl_ctx->ctx); -if (!store) - { -crypto_msg (M_FATAL ,"Cannot get certificate store" ); - } - -STACK_OF (X509_OBJECT ) *objs =X509_STORE_get0_objects (store); -for (int i =0 ; i <sk_X509_OBJECT_num (objs); i++) - { -X509_OBJECT *obj =sk_X509_OBJECT_value (objs, i); -ASSERT (obj); -if (X509_OBJECT_get_type (obj) ==X509_LU_CRL ) - { -return false; - } - } -return true; +return opt->ssl_ctx->crls ==NULL ||sk_X509_CRL_num (opt->ssl_ctx->crls) ==0 ; }#endif /* defined(ENABLE_CRYPTO_OPENSSL) */
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1289?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I31ac2a763209114267c35c4a9182a12d8d82f6fe
Gerrit-Change-Number: 1289
Gerrit-PatchSet: 3
Gerrit-Owner: davidben <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: davidben <[email protected]...>
Attention is currently required from: davidben, flichtenheld.
plaisthos has posted comments on this change by davidben. ( http://gerrit.openvpn.net/c/openvpn/+/1289?usp=email )
Change subject: ssl_openssl: Fix some CRL mixups
......................................................................
Patch Set 3: -Code-Review
(1 comment)
Patchset:
PS3:
I changed the patch slightly to work with the 1431 that fixes the problem that this patches runs into.
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1289?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I31ac2a763209114267c35c4a9182a12d8d82f6fe
Gerrit-Change-Number: 1289
Gerrit-PatchSet: 3
Gerrit-Owner: davidben <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: davidben <[email protected]...>
Gerrit-Comment-Date: Wed, 10 Dec 2025 15:42:56 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Attention is currently required from: davidben, flichtenheld.
plaisthos has posted comments on this change by davidben. ( http://gerrit.openvpn.net/c/openvpn/+/1289?usp=email )
Change subject: ssl_openssl: Fix some CRL mixups
......................................................................
Patch Set 9: Code-Review+2
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1289?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I31ac2a763209114267c35c4a9182a12d8d82f6fe
Gerrit-Change-Number: 1289
Gerrit-PatchSet: 9
Gerrit-Owner: davidben <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: davidben <[email protected]...>
Gerrit-Comment-Date: Tue, 31 Mar 2026 16:30:05 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Attention is currently required from: davidben, flichtenheld.
plaisthos has posted comments on this change by davidben. ( http://gerrit.openvpn.net/c/openvpn/+/1289?usp=email )
Change subject: ssl_openssl: Fix some CRL mixups
......................................................................
Patch Set 9:
(1 comment)
Patchset:
PS9:
I gave the patch a +2 but there some part of the patch that I adjusted when I needed to rebase it, so probably not a full +2 ack.
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1289?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I31ac2a763209114267c35c4a9182a12d8d82f6fe
Gerrit-Change-Number: 1289
Gerrit-PatchSet: 9
Gerrit-Owner: davidben <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: davidben <[email protected]...>
Gerrit-Comment-Date: Tue, 31 Mar 2026 16:30:38 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Attention is currently required from: davidben, flichtenheld, plaisthos.
plaisthos has uploaded a new patch set (#10) to the change originally created by davidben. ( http://gerrit.openvpn.net/c/openvpn/+/1289?usp=email )
The following approvals got outdated and were removed:
Code-Review+2 by plaisthos
Change subject: ssl_openssl: Fix some CRL mixups
......................................................................
ssl_openssl: Fix some CRL mixups
There are two ways to load CRLs in OpenSSL. They can be loaded at the X509_STORE, shared across verifications, or loaded per verification at the X509_STORE_CTX.
OpenVPN currently does the former. However, it also supports CRL reloading, and tries to reload the CRL file before each connection. OpenSSL does not really have a good way to unload objects from an X509_STORE. OpenVPN currently does it by grabbing the STACK_OF(X509_OBJECT) out of the X509_STORE and manually deleting all the CRLs from it.
This mutates an OpenSSL internal object which bumps into problems if OpenSSL ever switches to a more efficient representation. See
https://github.com/openssl/openssl/pull/28599
(It's also not thread-safe, though it doesn't look like that impacts OpenVPN? Actually even reading that list doesn't work. See CVE-2024-0397. This OpenSSL API was simply broken.)
Additionally, this seems to cause two OpenVPN features to not work together. I gather backend_tls_ctx_reload_crl is trying to clear the CRLs loaded from last time it ran. But tls_ctx_load_ca with a ca_file can also load CRLs. tls_ctx_load_ca with ca_path will also pick up CRLs and backend_tls_ctx_reload_crl actually ends up clobbering some state X509_LOOKUP_hash_dir internally maintains on the X509_STORE. Likewise, tls_verify_crl_missing can get confused between backend_tls_ctx_reload_crl's crl_file-based CRLs and CRLs from tls_ctx_load_ca.
Avoid all this by tracking the two CRLs separately. crl_file-based CRLs now go onto a STACK_OF(X509_CRL) tracked on the tls_root_ctx. Now this field can be freely reloaded by OpenVPN without reconfiguring OpenSSL. Instead, pass the current value into OpenSSL at verification time. To do so, we need to use the SSL_CTX_set_cert_verify_callback, which allows swapping out the X509_verify_cert call, and also tweaking the X509_STORE_CTX configuration before starting certificate verification.
Context: SSL_CTX_set_cert_verify_callback and the existing verify_callback are not the same. SSL_CTX_set_cert_verify_callback wraps the verification while verify_callback is called multiple times throughout verification. It's too late to reconfigure X509_STORE_CTX in verify_callback. verify_callback is usually not what you want. Sometimes current_cert and error_depth don't quite line up, and cert_hash_remember may end up called multiple times for a single certificate.
I suspect some of the other verify_callback logic would also be better done in the new callback, but I've left it alone to keep this change minimal. verify_callback is really only usable for suppressing errors. Application bookkeeping is better down elsewhere.
Add .clang-format section for STACK_OF since we otherwise format the line as STACK_OF(X509_CRL) * crls
---
M .clang-format
M src/openvpn/openssl_compat.h
M src/openvpn/ssl_openssl.c
M src/openvpn/ssl_openssl.h
M src/openvpn/ssl_verify_openssl.c
5 files changed, 38 insertions(+), 55 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/89/1289/10
.clang-format +4 -1
@@ -43,7 +43,10 @@ SpacesBeforeTrailingComments: '2' SpacesInParens: Never TabWidth: '4' -TypeNames: [DWORD] +TypeNames: + - 'DWORD' + - 'STACK_OF' +TypenameMacros: ['STACK_OF'] UseTab: Never WhitespaceSensitiveMacros: [_STRINGIFY] ---
src/openvpn/openssl_compat.h +0 -15
@@ -61,21 +61,6 @@/* Functionality missing in LibreSSL before 3.5 */ #if defined(LIBRESSL_VERSION_NUMBER ) &&LIBRESSL_VERSION_NUMBER <0x3050000fL -/** -* Destroy a X509 object -* -* @param obj X509 object -*/ -static inline void -X509_OBJECT_free (X509_OBJECT *obj) -{ -if (obj) - { -X509_OBJECT_free_contents (obj); -OPENSSL_free (obj); - } -} -#define EVP_CTRL_AEAD_SET_TAG EVP_CTRL_GCM_SET_TAG#define EVP_CTRL_AEAD_GET_TAG EVP_CTRL_GCM_GET_TAG#endif
src/openvpn/ssl_openssl.c +32 -22
101 lines not on this page · raw message
src/openvpn/ssl_openssl.h +1 -0
@@ -41,6 +41,7 @@SSL_CTX *ctx;time_t crl_last_mtime;off_t crl_last_size; +STACK_OF (X509_CRL ) *crls; };struct key_state_ssl
src/openvpn/ssl_verify_openssl.c +1 -17
@@ -783,23 +783,7 @@ return false; } -X509_STORE *store =SSL_CTX_get_cert_store (opt->ssl_ctx->ctx); -if (!store) - { -crypto_msg (M_FATAL ,"Cannot get certificate store" ); - } - -STACK_OF (X509_OBJECT ) *objs =X509_STORE_get0_objects (store); -for (int i =0 ; i <sk_X509_OBJECT_num (objs); i++) - { -X509_OBJECT *obj =sk_X509_OBJECT_value (objs, i); -ASSERT (obj); -if (X509_OBJECT_get_type (obj) ==X509_LU_CRL ) - { -return false; - } - } -return true; +return opt->ssl_ctx->crls ==NULL ||sk_X509_CRL_num (opt->ssl_ctx->crls) ==0 ; }#endif /* defined(ENABLE_CRYPTO_OPENSSL) */
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1289?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I31ac2a763209114267c35c4a9182a12d8d82f6fe
Gerrit-Change-Number: 1289
Gerrit-PatchSet: 10
Gerrit-Owner: davidben <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: davidben <[email protected]...>
Attention is currently required from: davidben, flichtenheld.
plaisthos has posted comments on this change by davidben. ( http://gerrit.openvpn.net/c/openvpn/+/1289?usp=email )
Change subject: ssl_openssl: Fix some CRL mixups
......................................................................
Patch Set 10: Code-Review+2
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1289?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I31ac2a763209114267c35c4a9182a12d8d82f6fe
Gerrit-Change-Number: 1289
Gerrit-PatchSet: 10
Gerrit-Owner: davidben <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: davidben <[email protected]...>
Gerrit-Comment-Date: Tue, 31 Mar 2026 22:50:08 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Attention is currently required from: davidben, flichtenheld.
plaisthos has uploaded a new patch set (#11) to the change originally created by davidben. ( http://gerrit.openvpn.net/c/openvpn/+/1289?usp=email )
The change is no longer submittable: checks~ChecksSubmitRule is unsatisfied now.
Change subject: ssl_openssl: Fix some CRL mixups
......................................................................
ssl_openssl: Fix some CRL mixups
There are two ways to load CRLs in OpenSSL. They can be loaded at the X509_STORE, shared across verifications, or loaded per verification at the X509_STORE_CTX.
OpenVPN currently does the former. However, it also supports CRL reloading, and tries to reload the CRL file before each connection. OpenSSL does not really have a good way to unload objects from an X509_STORE. OpenVPN currently does it by grabbing the STACK_OF(X509_OBJECT) out of the X509_STORE and manually deleting all the CRLs from it.
This mutates an OpenSSL internal object which bumps into problems if OpenSSL ever switches to a more efficient representation. See
https://github.com/openssl/openssl/pull/28599
(It's also not thread-safe, though it doesn't look like that impacts OpenVPN? Actually even reading that list doesn't work. See CVE-2024-0397. This OpenSSL API was simply broken.)
Additionally, this seems to cause two OpenVPN features to not work together. I gather backend_tls_ctx_reload_crl is trying to clear the CRLs loaded from last time it ran. But tls_ctx_load_ca with a ca_file can also load CRLs. tls_ctx_load_ca with ca_path will also pick up CRLs and backend_tls_ctx_reload_crl actually ends up clobbering some state X509_LOOKUP_hash_dir internally maintains on the X509_STORE. Likewise, tls_verify_crl_missing can get confused between backend_tls_ctx_reload_crl's crl_file-based CRLs and CRLs from tls_ctx_load_ca.
Avoid all this by tracking the two CRLs separately. crl_file-based CRLs now go onto a STACK_OF(X509_CRL) tracked on the tls_root_ctx. Now this field can be freely reloaded by OpenVPN without reconfiguring OpenSSL. Instead, pass the current value into OpenSSL at verification time. To do so, we need to use the SSL_CTX_set_cert_verify_callback, which allows swapping out the X509_verify_cert call, and also tweaking the X509_STORE_CTX configuration before starting certificate verification.
Context: SSL_CTX_set_cert_verify_callback and the existing verify_callback are not the same. SSL_CTX_set_cert_verify_callback wraps the verification while verify_callback is called multiple times throughout verification. It's too late to reconfigure X509_STORE_CTX in verify_callback. verify_callback is usually not what you want. Sometimes current_cert and error_depth don't quite line up, and cert_hash_remember may end up called multiple times for a single certificate.
I suspect some of the other verify_callback logic would also be better done in the new callback, but I've left it alone to keep this change minimal. verify_callback is really only usable for suppressing errors. Application bookkeeping is better down elsewhere.
Add .clang-format section for STACK_OF since we otherwise format the line as STACK_OF(X509_CRL) * crls
---
M .clang-format
M src/openvpn/openssl_compat.h
M src/openvpn/ssl_openssl.c
M src/openvpn/ssl_openssl.h
M src/openvpn/ssl_verify_openssl.c
5 files changed, 38 insertions(+), 55 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/89/1289/11
.clang-format +4 -1
@@ -43,7 +43,10 @@ SpacesBeforeTrailingComments: '2' SpacesInParens: Never TabWidth: '4' -TypeNames: [DWORD] +TypeNames: + - 'DWORD' + - 'STACK_OF' +TypenameMacros: ['STACK_OF'] UseTab: Never WhitespaceSensitiveMacros: [_STRINGIFY] ---
src/openvpn/openssl_compat.h +0 -15
@@ -61,21 +61,6 @@/* Functionality missing in LibreSSL before 3.5 */ #if defined(LIBRESSL_VERSION_NUMBER ) &&LIBRESSL_VERSION_NUMBER <0x3050000fL -/** -* Destroy a X509 object -* -* @param obj X509 object -*/ -static inline void -X509_OBJECT_free (X509_OBJECT *obj) -{ -if (obj) - { -X509_OBJECT_free_contents (obj); -OPENSSL_free (obj); - } -} -#define EVP_CTRL_AEAD_SET_TAG EVP_CTRL_GCM_SET_TAG#define EVP_CTRL_AEAD_GET_TAG EVP_CTRL_GCM_GET_TAG#endif
src/openvpn/ssl_openssl.c +32 -22
101 lines not on this page · raw message
src/openvpn/ssl_openssl.h +1 -0
@@ -41,6 +41,7 @@SSL_CTX *ctx;time_t crl_last_mtime;off_t crl_last_size; +STACK_OF (X509_CRL ) *crls; };struct key_state_ssl
src/openvpn/ssl_verify_openssl.c +1 -17
@@ -785,23 +785,7 @@ return false; } -X509_STORE *store =SSL_CTX_get_cert_store (opt->ssl_ctx->ctx); -if (!store) - { -crypto_msg (M_FATAL ,"Cannot get certificate store" ); - } - -STACK_OF (X509_OBJECT ) *objs =X509_STORE_get0_objects (store); -for (int i =0 ; i <sk_X509_OBJECT_num (objs); i++) - { -X509_OBJECT *obj =sk_X509_OBJECT_value (objs, i); -ASSERT (obj); -if (X509_OBJECT_get_type (obj) ==X509_LU_CRL ) - { -return false; - } - } -return true; +return opt->ssl_ctx->crls ==NULL ||sk_X509_CRL_num (opt->ssl_ctx->crls) ==0 ; }#endif /* defined(ENABLE_CRYPTO_OPENSSL) */
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1289?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I31ac2a763209114267c35c4a9182a12d8d82f6fe
Gerrit-Change-Number: 1289
Gerrit-PatchSet: 11
Gerrit-Owner: davidben <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: davidben <[email protected]...>
Attention is currently required from: davidben, flichtenheld.
flichtenheld has uploaded a new patch set (#12) to the change originally created by davidben. ( http://gerrit.openvpn.net/c/openvpn/+/1289?usp=email )
The change is no longer submittable: checks~ChecksSubmitRule is unsatisfied now.
Change subject: ssl_openssl: Fix some CRL mixups
......................................................................
ssl_openssl: Fix some CRL mixups
There are two ways to load CRLs in OpenSSL. They can be loaded at the X509_STORE, shared across verifications, or loaded per verification at the X509_STORE_CTX.
OpenVPN currently does the former. However, it also supports CRL reloading, and tries to reload the CRL file before each connection. OpenSSL does not really have a good way to unload objects from an X509_STORE. OpenVPN currently does it by grabbing the STACK_OF(X509_OBJECT) out of the X509_STORE and manually deleting all the CRLs from it.
This mutates an OpenSSL internal object which bumps into problems if OpenSSL ever switches to a more efficient representation. See
https://github.com/openssl/openssl/pull/28599
(It's also not thread-safe, though it doesn't look like that impacts OpenVPN? Actually even reading that list doesn't work. See CVE-2024-0397. This OpenSSL API was simply broken.)
Additionally, this seems to cause two OpenVPN features to not work together. I gather backend_tls_ctx_reload_crl is trying to clear the CRLs loaded from last time it ran. But tls_ctx_load_ca with a ca_file can also load CRLs. tls_ctx_load_ca with ca_path will also pick up CRLs and backend_tls_ctx_reload_crl actually ends up clobbering some state X509_LOOKUP_hash_dir internally maintains on the X509_STORE. Likewise, tls_verify_crl_missing can get confused between backend_tls_ctx_reload_crl's crl_file-based CRLs and CRLs from tls_ctx_load_ca.
Avoid all this by tracking the two CRLs separately. crl_file-based CRLs now go onto a STACK_OF(X509_CRL) tracked on the tls_root_ctx. Now this field can be freely reloaded by OpenVPN without reconfiguring OpenSSL. Instead, pass the current value into OpenSSL at verification time. To do so, we need to use the SSL_CTX_set_cert_verify_callback, which allows swapping out the X509_verify_cert call, and also tweaking the X509_STORE_CTX configuration before starting certificate verification.
Context: SSL_CTX_set_cert_verify_callback and the existing verify_callback are not the same. SSL_CTX_set_cert_verify_callback wraps the verification while verify_callback is called multiple times throughout verification. It's too late to reconfigure X509_STORE_CTX in verify_callback. verify_callback is usually not what you want. Sometimes current_cert and error_depth don't quite line up, and cert_hash_remember may end up called multiple times for a single certificate.
I suspect some of the other verify_callback logic would also be better done in the new callback, but I've left it alone to keep this change minimal. verify_callback is really only usable for suppressing errors. Application bookkeeping is better down elsewhere.
Add .clang-format section for STACK_OF since we otherwise format the line as STACK_OF(X509_CRL) * crls
---
M .clang-format
M src/openvpn/openssl_compat.h
M src/openvpn/ssl_openssl.c
M src/openvpn/ssl_openssl.h
M src/openvpn/ssl_verify_openssl.c
5 files changed, 38 insertions(+), 55 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/89/1289/12
.clang-format +4 -1
@@ -43,7 +43,10 @@ SpacesBeforeTrailingComments: '2' SpacesInParens: Never TabWidth: '4' -TypeNames: [DWORD] +TypeNames: + - 'DWORD' + - 'STACK_OF' +TypenameMacros: ['STACK_OF'] UseTab: Never WhitespaceSensitiveMacros: [_STRINGIFY] ---
src/openvpn/openssl_compat.h +0 -15
@@ -61,21 +61,6 @@/* Functionality missing in LibreSSL before 3.5 */ #if defined(LIBRESSL_VERSION_NUMBER ) &&LIBRESSL_VERSION_NUMBER <0x3050000fL -/** -* Destroy a X509 object -* -* @param obj X509 object -*/ -static inline void -X509_OBJECT_free (X509_OBJECT *obj) -{ -if (obj) - { -X509_OBJECT_free_contents (obj); -OPENSSL_free (obj); - } -} -#define EVP_CTRL_AEAD_SET_TAG EVP_CTRL_GCM_SET_TAG#define EVP_CTRL_AEAD_GET_TAG EVP_CTRL_GCM_GET_TAG#endif
src/openvpn/ssl_openssl.c +32 -22
101 lines not on this page · raw message
src/openvpn/ssl_openssl.h +1 -0
@@ -41,6 +41,7 @@SSL_CTX *ctx;time_t crl_last_mtime;off_t crl_last_size; +STACK_OF (X509_CRL ) *crls; };struct key_state_ssl
src/openvpn/ssl_verify_openssl.c +1 -17
@@ -798,23 +798,7 @@ return false; } -X509_STORE *store =SSL_CTX_get_cert_store (opt->ssl_ctx->ctx); -if (!store) - { -crypto_msg (M_FATAL ,"Cannot get certificate store" ); - } - -STACK_OF (X509_OBJECT ) *objs =X509_STORE_get0_objects (store); -for (int i =0 ; i <sk_X509_OBJECT_num (objs); i++) - { -X509_OBJECT *obj =sk_X509_OBJECT_value (objs, i); -ASSERT (obj); -if (X509_OBJECT_get_type (obj) ==X509_LU_CRL ) - { -return false; - } - } -return true; +return opt->ssl_ctx->crls ==NULL ||sk_X509_CRL_num (opt->ssl_ctx->crls) ==0 ; }#endif /* defined(ENABLE_CRYPTO_OPENSSL) */
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1289?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I31ac2a763209114267c35c4a9182a12d8d82f6fe
Gerrit-Change-Number: 1289
Gerrit-PatchSet: 12
Gerrit-Owner: davidben <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: davidben <[email protected]...>
Attention is currently required from: davidben, flichtenheld.
MaxF has posted comments on this change by davidben. ( http://gerrit.openvpn.net/c/openvpn/+/1289?usp=email )
Change subject: ssl_openssl: Fix some CRL mixups
......................................................................
Patch Set 12:
(2 comments)
Patchset:
PS12:
This makes sense to me, but I don't know these functions in-depth. Just one question about how exactly X509_STORE_CTX_set0_crls() copies the CRLs.
File src/openvpn/ssl_openssl.c:
http://gerrit.openvpn.net/c/openvpn/+/1289/comment/c1a234c8_f81029f6?usp=email :
PS12, Line 321: X509_STORE_CTX_set0_crls(ctx, session->opt->ssl_ctx->crls);
Does this function copy the CRLs into ctx, or a pointer to them? If it's the latter, does this modified X509_STORE_CTX continue to exist inside the SSL_CTX after this callback? (What I'm getting at is, do we need to worry about dangling pointers if reload_crl is called?)
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1289?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I31ac2a763209114267c35c4a9182a12d8d82f6fe
Gerrit-Change-Number: 1289
Gerrit-PatchSet: 12
Gerrit-Owner: davidben <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: MaxF <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: davidben <[email protected]...>
Gerrit-Comment-Date: Wed, 15 Apr 2026 16:39:29 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Attention is currently required from: MaxF, flichtenheld.
davidben has posted comments on this change by davidben. ( http://gerrit.openvpn.net/c/openvpn/+/1289?usp=email )
Change subject: ssl_openssl: Fix some CRL mixups
......................................................................
Patch Set 12:
(1 comment)
File src/openvpn/ssl_openssl.c:
http://gerrit.openvpn.net/c/openvpn/+/1289/comment/4e11b60a_6a1828e8?usp=email :
PS12, Line 321: X509_STORE_CTX_set0_crls(ctx, session->opt->ssl_ctx->crls);
Quoted 1 line
Does this function copy the CRLs into ctx, or a pointer to them?
Pointer to them. set0 functions in OpenSSL generally are a pointer to them.
Quoted 1 line
If it's the latter, does this modified
X509_STORE_CTXcontinue to exist inside theSSL_CTXafter this callback?
Nope. OpenSSL is very inconsistent about the relationship between FOO and FOO_CTX. X509_STORE is shared configuration between certificate verifications, while X509_STORE_CTX is a single certificate verification operation. So this object will be freed shortly after this function returns. It's just a vehicle for passing the verification bits to the caller.
Quoted 1 line
(What I'm getting at is, do we need to worry about dangling pointers if
reload_crlis called?)
Should be OK!
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1289?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I31ac2a763209114267c35c4a9182a12d8d82f6fe
Gerrit-Change-Number: 1289
Gerrit-PatchSet: 12
Gerrit-Owner: davidben <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: MaxF <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: MaxF <[email protected]...>
Gerrit-Comment-Date: Wed, 15 Apr 2026 17:27:38 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: MaxF <[email protected]...>
Attention is currently required from: MaxF, davidben, flichtenheld.
plaisthos has posted comments on this change by davidben. ( http://gerrit.openvpn.net/c/openvpn/+/1289?usp=email )
Change subject: ssl_openssl: Fix some CRL mixups
......................................................................
Patch Set 12: Code-Review+2
(1 comment)
File src/openvpn/ssl_openssl.c:
http://gerrit.openvpn.net/c/openvpn/+/1289/comment/6820491f_1542525e?usp=email :
PS12, Line 321: X509_STORE_CTX_set0_crls(ctx, session->opt->ssl_ctx->crls);
Quoted 1 line
Does this function copy the CRLs into ctx, or a pointer to them? If it's the latter, does this modif […]
set0/get0 in OpenSSL terms mean no copy being made. We are really passing the pointer.
This is not super avoid but session->opt->ssl_ctx is a pointer that points to the global tls_root_ctx. Commit 44dd39b3ef actually makes it a real pointer. Before it was as well but in a very weird way that all the pointers in that ssl_ctx would point to a global object but ssl_ctx still being local.
The pointer is technically dangling but since we set that before every access of it (in the callback), the pointer is also always updated.
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1289?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I31ac2a763209114267c35c4a9182a12d8d82f6fe
Gerrit-Change-Number: 1289
Gerrit-PatchSet: 12
Gerrit-Owner: davidben <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: MaxF <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: davidben <[email protected]...>
Gerrit-Attention: MaxF <[email protected]...>
Gerrit-Comment-Date: Wed, 15 Apr 2026 18:16:05 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Comment-In-Reply-To: MaxF <[email protected]...>
Attention is currently required from: davidben, flichtenheld.
MaxF has posted comments on this change by davidben. ( http://gerrit.openvpn.net/c/openvpn/+/1289?usp=email )
Change subject: ssl_openssl: Fix some CRL mixups
......................................................................
Patch Set 12: Code-Review+2
(1 comment)
File src/openvpn/ssl_openssl.c:
http://gerrit.openvpn.net/c/openvpn/+/1289/comment/25db34bc_0e2d0916?usp=email :
PS12, Line 321: X509_STORE_CTX_set0_crls(ctx, session->opt->ssl_ctx->crls);
Quoted 1 line
set0/get0 in OpenSSL terms mean no copy being made. We are really passing the pointer. […]
Thanks for the explanations, I'll add my approval to this commit!
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1289?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I31ac2a763209114267c35c4a9182a12d8d82f6fe
Gerrit-Change-Number: 1289
Gerrit-PatchSet: 12
Gerrit-Owner: davidben <[email protected]...>
Gerrit-Reviewer: MaxF <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: davidben <[email protected]...>
Gerrit-Comment-Date: Wed, 15 Apr 2026 20:31:46 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Comment-In-Reply-To: plaisthos <[email protected]...>
Comment-In-Reply-To: MaxF <[email protected]...>
PATCH v12 1/1 ssl_openssl: Fix some CRL mixups
In reply to a message not in the archiveFrom: David Benjamin <[email protected]...>
There are two ways to load CRLs in OpenSSL. They can be loaded at the X509_STORE, shared across verifications, or loaded per verification at the X509_STORE_CTX.
OpenVPN currently does the former. However, it also supports CRL reloading, and tries to reload the CRL file before each connection. OpenSSL does not really have a good way to unload objects from an X509_STORE. OpenVPN currently does it by grabbing the STACK_OF(X509_OBJECT) out of the X509_STORE and manually deleting all the CRLs from it.
This mutates an OpenSSL internal object which bumps into problems if OpenSSL ever switches to a more efficient representation. See
https://github.com/openssl/openssl/pull/28599
(It's also not thread-safe, though it doesn't look like that impacts OpenVPN? Actually even reading that list doesn't work. See CVE-2024-0397. This OpenSSL API was simply broken.)
Additionally, this seems to cause two OpenVPN features to not work together. I gather backend_tls_ctx_reload_crl is trying to clear the CRLs loaded from last time it ran. But tls_ctx_load_ca with a ca_file can also load CRLs. tls_ctx_load_ca with ca_path will also pick up CRLs and backend_tls_ctx_reload_crl actually ends up clobbering some state X509_LOOKUP_hash_dir internally maintains on the X509_STORE. Likewise, tls_verify_crl_missing can get confused between backend_tls_ctx_reload_crl's crl_file-based CRLs and CRLs from tls_ctx_load_ca.
Avoid all this by tracking the two CRLs separately. crl_file-based CRLs now go onto a STACK_OF(X509_CRL) tracked on the tls_root_ctx. Now this field can be freely reloaded by OpenVPN without reconfiguring OpenSSL. Instead, pass the current value into OpenSSL at verification time. To do so, we need to use the SSL_CTX_set_cert_verify_callback, which allows swapping out the X509_verify_cert call, and also tweaking the X509_STORE_CTX configuration before starting certificate verification.
Context: SSL_CTX_set_cert_verify_callback and the existing verify_callback are not the same. SSL_CTX_set_cert_verify_callback wraps the verification while verify_callback is called multiple times throughout verification. It's too late to reconfigure X509_STORE_CTX in verify_callback. verify_callback is usually not what you want. Sometimes current_cert and error_depth don't quite line up, and cert_hash_remember may end up called multiple times for a single certificate.
I suspect some of the other verify_callback logic would also be better done in the new callback, but I've left it alone to keep this change minimal. verify_callback is really only usable for suppressing errors. Application bookkeeping is better down elsewhere.
Add .clang-format section for STACK_OF since we otherwise format the line as STACK_OF(X509_CRL) * crls
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1289
---
This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master.
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1289
This mail reflects revision 12 of this Change.
Acked-by according to Gerrit (reflected above):
Arne Schwabe <[email protected]...>
MaxF <[email protected]...>
.clang-format +4 -1
@@ -43,7 +43,10 @@ SpacesBeforeTrailingComments: '2' SpacesInParens: Never TabWidth: '4' -TypeNames: [DWORD] +TypeNames: + - 'DWORD' + - 'STACK_OF' +TypenameMacros: ['STACK_OF'] UseTab: Never WhitespaceSensitiveMacros: [_STRINGIFY] ---
src/openvpn/openssl_compat.h +0 -15
@@ -61,21 +61,6 @@/* Functionality missing in LibreSSL before 3.5 */ #if defined(LIBRESSL_VERSION_NUMBER ) &&LIBRESSL_VERSION_NUMBER <0x3050000fL -/** -* Destroy a X509 object -* -* @param obj X509 object -*/ -static inline void -X509_OBJECT_free (X509_OBJECT *obj) -{ -if (obj) - { -X509_OBJECT_free_contents (obj); -OPENSSL_free (obj); - } -} -#define EVP_CTRL_AEAD_SET_TAG EVP_CTRL_GCM_SET_TAG#define EVP_CTRL_AEAD_GET_TAG EVP_CTRL_GCM_GET_TAG#endif
src/openvpn/ssl_openssl.c +32 -22
101 lines not on this page · raw message
src/openvpn/ssl_openssl.h +1 -0
@@ -41,6 +41,7 @@SSL_CTX *ctx;time_t crl_last_mtime;off_t crl_last_size; +STACK_OF (X509_CRL ) *crls; };struct key_state_ssl
src/openvpn/ssl_verify_openssl.c +1 -17
@@ -798,23 +798,7 @@ return false; } -X509_STORE *store =SSL_CTX_get_cert_store (opt->ssl_ctx->ctx); -if (!store) - { -crypto_msg (M_FATAL ,"Cannot get certificate store" ); - } - -STACK_OF (X509_OBJECT ) *objs =X509_STORE_get0_objects (store); -for (int i =0 ; i <sk_X509_OBJECT_num (objs); i++) - { -X509_OBJECT *obj =sk_X509_OBJECT_value (objs, i); -ASSERT (obj); -if (X509_OBJECT_get_type (obj) ==X509_LU_CRL ) - { -return false; - } - } -return true; +return opt->ssl_ctx->crls ==NULL ||sk_X509_CRL_num (opt->ssl_ctx->crls) ==0 ; }#endif /* defined(ENABLE_CRYPTO_OPENSSL) */
[Openvpn-devel] [PATCH applied] Re: ssl_openssl: Fix some CRL mixups
So, finally. Thanks for helping us fix our OpenSSL interfacing code :-)
It took a bit, because of this and that, and releases getting in the way, and then finding a second pair of eyes to review the adjustments Arne did. But now we have nice code that makes buildbot and my local tests happy (which do not use CRLs... but that should be somewhat easy to add to the CI testing - create a dedicated client cert that is then revoked right away, file that under "must fail" t_client tests).
Your patch has been applied to the master and release/2.7 branch (long-term compat with OpenSSL 4.0).
I'm not sure about 2.6 - it's not a "hard bug" as the existing code sort-of-works, and 2.6 will never see OpenSSL 4.0 compat fixes now that 2.7 is the main release under maintenance. So I went for "not needed, and only real bugfixes go to 2.6 now". Further, it wouldn't work as is anyway (gerrit 1431 is not in 2.6)...
commit 2befad4de1b4da3c06c5fb3537a767ac1d058eb3 (master) commit 0588668f4d12f6a1b87f1cf94f4d8ee96cadbf26 (release/2.7)
Author: David Benjamin Date: Thu Apr 16 19:41:35 2026 +0200
ssl_openssl: Fix some CRL mixups
Signed-off-by: David Benjamin <[email protected]...>
Signed-off-by: Arne Schwabe <[email protected]...>
Acked-by: Arne Schwabe <[email protected]...>
Acked-by: MaxF <[email protected]...>
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1289
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg36641.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
cron2 has uploaded a new patch set (#13) to the change originally created by davidben. ( http://gerrit.openvpn.net/c/openvpn/+/1289?usp=email )
The following approvals got outdated and were removed:
Code-Review+2 by MaxF, Code-Review+2 by plaisthos
Change subject: ssl_openssl: Fix some CRL mixups
......................................................................
ssl_openssl: Fix some CRL mixups
There are two ways to load CRLs in OpenSSL. They can be loaded at the X509_STORE, shared across verifications, or loaded per verification at the X509_STORE_CTX.
OpenVPN currently does the former. However, it also supports CRL reloading, and tries to reload the CRL file before each connection. OpenSSL does not really have a good way to unload objects from an X509_STORE. OpenVPN currently does it by grabbing the STACK_OF(X509_OBJECT) out of the X509_STORE and manually deleting all the CRLs from it.
This mutates an OpenSSL internal object which bumps into problems if OpenSSL ever switches to a more efficient representation. See
https://github.com/openssl/openssl/pull/28599
(It's also not thread-safe, though it doesn't look like that impacts OpenVPN? Actually even reading that list doesn't work. See CVE-2024-0397. This OpenSSL API was simply broken.)
Additionally, this seems to cause two OpenVPN features to not work together. I gather backend_tls_ctx_reload_crl is trying to clear the CRLs loaded from last time it ran. But tls_ctx_load_ca with a ca_file can also load CRLs. tls_ctx_load_ca with ca_path will also pick up CRLs and backend_tls_ctx_reload_crl actually ends up clobbering some state X509_LOOKUP_hash_dir internally maintains on the X509_STORE. Likewise, tls_verify_crl_missing can get confused between backend_tls_ctx_reload_crl's crl_file-based CRLs and CRLs from tls_ctx_load_ca.
Avoid all this by tracking the two CRLs separately. crl_file-based CRLs now go onto a STACK_OF(X509_CRL) tracked on the tls_root_ctx. Now this field can be freely reloaded by OpenVPN without reconfiguring OpenSSL. Instead, pass the current value into OpenSSL at verification time. To do so, we need to use the SSL_CTX_set_cert_verify_callback, which allows swapping out the X509_verify_cert call, and also tweaking the X509_STORE_CTX configuration before starting certificate verification.
Context: SSL_CTX_set_cert_verify_callback and the existing verify_callback are not the same. SSL_CTX_set_cert_verify_callback wraps the verification while verify_callback is called multiple times throughout verification. It's too late to reconfigure X509_STORE_CTX in verify_callback. verify_callback is usually not what you want. Sometimes current_cert and error_depth don't quite line up, and cert_hash_remember may end up called multiple times for a single certificate.
I suspect some of the other verify_callback logic would also be better done in the new callback, but I've left it alone to keep this change minimal. verify_callback is really only usable for suppressing errors. Application bookkeeping is better down elsewhere.
Add .clang-format section for STACK_OF since we otherwise format the line as STACK_OF(X509_CRL) * crls
Github: see also openssl/openssl#28599
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1289
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg36641.html
---
M .clang-format
M src/openvpn/openssl_compat.h
M src/openvpn/ssl_openssl.c
M src/openvpn/ssl_openssl.h
M src/openvpn/ssl_verify_openssl.c
5 files changed, 38 insertions(+), 55 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/89/1289/13
.clang-format +4 -1
@@ -43,7 +43,10 @@ SpacesBeforeTrailingComments: '2' SpacesInParens: Never TabWidth: '4' -TypeNames: [DWORD] +TypeNames: + - 'DWORD' + - 'STACK_OF' +TypenameMacros: ['STACK_OF'] UseTab: Never WhitespaceSensitiveMacros: [_STRINGIFY] ---
src/openvpn/openssl_compat.h +0 -15
@@ -61,21 +61,6 @@/* Functionality missing in LibreSSL before 3.5 */ #if defined(LIBRESSL_VERSION_NUMBER ) &&LIBRESSL_VERSION_NUMBER <0x3050000fL -/** -* Destroy a X509 object -* -* @param obj X509 object -*/ -static inline void -X509_OBJECT_free (X509_OBJECT *obj) -{ -if (obj) - { -X509_OBJECT_free_contents (obj); -OPENSSL_free (obj); - } -} -#define EVP_CTRL_AEAD_SET_TAG EVP_CTRL_GCM_SET_TAG#define EVP_CTRL_AEAD_GET_TAG EVP_CTRL_GCM_GET_TAG#endif
src/openvpn/ssl_openssl.c +32 -22
101 lines not on this page · raw message
src/openvpn/ssl_openssl.h +1 -0
@@ -41,6 +41,7 @@SSL_CTX *ctx;time_t crl_last_mtime;off_t crl_last_size; +STACK_OF (X509_CRL ) *crls; };struct key_state_ssl
src/openvpn/ssl_verify_openssl.c +1 -17
@@ -808,23 +808,7 @@ return false; } -X509_STORE *store =SSL_CTX_get_cert_store (opt->ssl_ctx->ctx); -if (!store) - { -crypto_msg (M_FATAL ,"Cannot get certificate store" ); - } - -STACK_OF (X509_OBJECT ) *objs =X509_STORE_get0_objects (store); -for (int i =0 ; i <sk_X509_OBJECT_num (objs); i++) - { -X509_OBJECT *obj =sk_X509_OBJECT_value (objs, i); -ASSERT (obj); -if (X509_OBJECT_get_type (obj) ==X509_LU_CRL ) - { -return false; - } - } -return true; +return opt->ssl_ctx->crls ==NULL ||sk_X509_CRL_num (opt->ssl_ctx->crls) ==0 ; }#endif /* defined(ENABLE_CRYPTO_OPENSSL) */
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1289?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I31ac2a763209114267c35c4a9182a12d8d82f6fe
Gerrit-Change-Number: 1289
Gerrit-PatchSet: 13
Gerrit-Owner: davidben <[email protected]...>
Gerrit-Reviewer: MaxF <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/1289?usp=email )
Change subject: ssl_openssl: Fix some CRL mixups
......................................................................
ssl_openssl: Fix some CRL mixups
There are two ways to load CRLs in OpenSSL. They can be loaded at the X509_STORE, shared across verifications, or loaded per verification at the X509_STORE_CTX.
OpenVPN currently does the former. However, it also supports CRL reloading, and tries to reload the CRL file before each connection. OpenSSL does not really have a good way to unload objects from an X509_STORE. OpenVPN currently does it by grabbing the STACK_OF(X509_OBJECT) out of the X509_STORE and manually deleting all the CRLs from it.
This mutates an OpenSSL internal object which bumps into problems if OpenSSL ever switches to a more efficient representation. See
https://github.com/openssl/openssl/pull/28599
(It's also not thread-safe, though it doesn't look like that impacts OpenVPN? Actually even reading that list doesn't work. See CVE-2024-0397. This OpenSSL API was simply broken.)
Additionally, this seems to cause two OpenVPN features to not work together. I gather backend_tls_ctx_reload_crl is trying to clear the CRLs loaded from last time it ran. But tls_ctx_load_ca with a ca_file can also load CRLs. tls_ctx_load_ca with ca_path will also pick up CRLs and backend_tls_ctx_reload_crl actually ends up clobbering some state X509_LOOKUP_hash_dir internally maintains on the X509_STORE. Likewise, tls_verify_crl_missing can get confused between backend_tls_ctx_reload_crl's crl_file-based CRLs and CRLs from tls_ctx_load_ca.
Avoid all this by tracking the two CRLs separately. crl_file-based CRLs now go onto a STACK_OF(X509_CRL) tracked on the tls_root_ctx. Now this field can be freely reloaded by OpenVPN without reconfiguring OpenSSL. Instead, pass the current value into OpenSSL at verification time. To do so, we need to use the SSL_CTX_set_cert_verify_callback, which allows swapping out the X509_verify_cert call, and also tweaking the X509_STORE_CTX configuration before starting certificate verification.
Context: SSL_CTX_set_cert_verify_callback and the existing verify_callback are not the same. SSL_CTX_set_cert_verify_callback wraps the verification while verify_callback is called multiple times throughout verification. It's too late to reconfigure X509_STORE_CTX in verify_callback. verify_callback is usually not what you want. Sometimes current_cert and error_depth don't quite line up, and cert_hash_remember may end up called multiple times for a single certificate.
I suspect some of the other verify_callback logic would also be better done in the new callback, but I've left it alone to keep this change minimal. verify_callback is really only usable for suppressing errors. Application bookkeeping is better down elsewhere.
Add .clang-format section for STACK_OF since we otherwise format the line as STACK_OF(X509_CRL) * crls
Github: see also openssl/openssl#28599
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1289
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg36641.html
---
M .clang-format
M src/openvpn/openssl_compat.h
M src/openvpn/ssl_openssl.c
M src/openvpn/ssl_openssl.h
M src/openvpn/ssl_verify_openssl.c
5 files changed, 38 insertions(+), 55 deletions(-)
.clang-format +4 -1
@@ -43,7 +43,10 @@ SpacesBeforeTrailingComments: '2' SpacesInParens: Never TabWidth: '4' -TypeNames: [DWORD] +TypeNames: + - 'DWORD' + - 'STACK_OF' +TypenameMacros: ['STACK_OF'] UseTab: Never WhitespaceSensitiveMacros: [_STRINGIFY] ---
src/openvpn/openssl_compat.h +0 -15
@@ -61,21 +61,6 @@/* Functionality missing in LibreSSL before 3.5 */ #if defined(LIBRESSL_VERSION_NUMBER ) &&LIBRESSL_VERSION_NUMBER <0x3050000fL -/** -* Destroy a X509 object -* -* @param obj X509 object -*/ -static inline void -X509_OBJECT_free (X509_OBJECT *obj) -{ -if (obj) - { -X509_OBJECT_free_contents (obj); -OPENSSL_free (obj); - } -} -#define EVP_CTRL_AEAD_SET_TAG EVP_CTRL_GCM_SET_TAG#define EVP_CTRL_AEAD_GET_TAG EVP_CTRL_GCM_GET_TAG#endif
src/openvpn/ssl_openssl.c +32 -22
101 lines not on this page · raw message
src/openvpn/ssl_openssl.h +1 -0
@@ -41,6 +41,7 @@SSL_CTX *ctx;time_t crl_last_mtime;off_t crl_last_size; +STACK_OF (X509_CRL ) *crls; };struct key_state_ssl
src/openvpn/ssl_verify_openssl.c +1 -17
@@ -808,23 +808,7 @@ return false; } -X509_STORE *store =SSL_CTX_get_cert_store (opt->ssl_ctx->ctx); -if (!store) - { -crypto_msg (M_FATAL ,"Cannot get certificate store" ); - } - -STACK_OF (X509_OBJECT ) *objs =X509_STORE_get0_objects (store); -for (int i =0 ; i <sk_X509_OBJECT_num (objs); i++) - { -X509_OBJECT *obj =sk_X509_OBJECT_value (objs, i); -ASSERT (obj); -if (X509_OBJECT_get_type (obj) ==X509_LU_CRL ) - { -return false; - } - } -return true; +return opt->ssl_ctx->crls ==NULL ||sk_X509_CRL_num (opt->ssl_ctx->crls) ==0 ; }#endif /* defined(ENABLE_CRYPTO_OPENSSL) */
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1289?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I31ac2a763209114267c35c4a9182a12d8d82f6fe
Gerrit-Change-Number: 1289
Gerrit-PatchSet: 13
Gerrit-Owner: davidben <[email protected]...>
Gerrit-Reviewer: MaxF <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>